home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_interrupts.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  12.5 KB  |  377 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. static APTR intmoretext0,intmoretext1,intmoretext2,intmoretext3;
  33.  
  34. static APTR IntPool = NULL;
  35.  
  36. static UBYTE *intType[] = {
  37.    "TBE (ser.transmit buffer empty)",
  38.    "DSKBLK (disk block complete)",
  39.    "SOFTINT (software interrupt)",
  40.    "PORTS (external INT2 & CIAA)",
  41.    "COPPER (graphics coprocessor)",
  42.    "VERTB (vertical blank interval)",
  43.    "BLITTER (blitter finished)",
  44.    "AUDIO0 (audio channel 0)",
  45.    "AUDIO1 (audio channel 1)",
  46.    "AUDIO2 (audio channel 2)",
  47.    "AUDIO3 (audio channel 3)",
  48.    "RBF (ser. receive buffer full)",
  49.    "DSKSYNC (disk sync patt. found)",
  50.    "EXTER (external INT6 & CIAB)",
  51.    "INTEN (special (master enable))",
  52.    "NMI (non-maskable interrupt)"
  53. };
  54.  
  55. static UBYTE *intTypeShort[] = {
  56.    "Serial Out",
  57.    "Disk Block",
  58.    "SoftInt",
  59.    "INT2/CIAA",
  60.    "Copper",
  61.    "Vertical Blank",
  62.    "Blitter",
  63.    "Audio 0",
  64.    "Audio 1",
  65.    "Audio 2",
  66.    "Audio 3",
  67.    "Serial In",
  68.    "Disk Sync",
  69.    "INT6/CIAB",
  70.    "INTEN",
  71.    "NMI"
  72. };
  73.  
  74. __asm __saveds LONG intlist_dspfunc(register __a2 char **array, register __a1 struct IntEntry *intentry, register __a0 struct Hook *hook)
  75. {
  76.    if (intentry) {
  77.       *array++ = intentry->int_address;
  78.       *array++ = intentry->int_name;
  79.       *array++ = intentry->int_pri;
  80.       *array++ = intentry->int_data;
  81.       *array++ = intentry->int_code;
  82.       *array++ = intentry->int_num;
  83.       *array++ = intentry->int_kind;
  84.       *array   = NULL;
  85.    } else {
  86.       *array++ = ESC "bAddress";
  87.       *array++ = ESC "bln_Name";
  88.       *array++ = ESC "bln_Pri";
  89.       *array++ = ESC "bis_Data";
  90.       *array++ = ESC "bis_Code";
  91.       *array++ = ESC "bInterrupt";
  92.       *array++ = ESC "bIntType";
  93.       *array   = NULL;
  94.    }
  95.    return(0);
  96. }
  97.  
  98. struct Hook intlist_dsphook = {
  99.  {NULL, NULL},
  100.  (ULONG (* )())intlist_dspfunc,
  101.  NULL, NULL
  102. };
  103.  
  104. void FreeInterrupts (void)
  105. {
  106.     MyFreePoolStructs (&IntPool, inttext, NULL, intlist);
  107. }
  108.  
  109. APTR GetInterrupts (int si_job, char *name, struct IntEntry **first) {
  110.    struct   IntVector   *intvec;
  111.    struct   Interrupt   *intr,*intradr;
  112.    char     *mark;
  113.    struct   Node        *intnode;
  114.    struct   IntEntry    *intentry,*previous = NULL;
  115.    int      i;
  116.  
  117.    int intcnt = 0;
  118.    if (first)
  119.       *first = 0;
  120.  
  121.    if (!IntPool) IntPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  122.  
  123.    IsHex (name, (long *) &intradr);
  124.  
  125.    if (clientstate) {
  126.       if (SendDaemon ("GetIntList")) {
  127.          while ((intentry = tbAllocPooled(IntPool, sizeof(struct IntEntry))) \
  128.            && (ReceiveDecodedEntry ((UBYTE *) intentry, sizeof (struct IntEntry)))) {
  129.             IsHex (intentry->int_address, (long *) &intentry->int_adr);
  130.  
  131.             if (! *first)
  132.                *first = intentry;
  133.             if (previous)
  134.                previous->int_next = intentry;
  135.  
  136.             intcnt++;
  137.             previous = intentry;
  138.          }
  139.       }
  140.    } else {
  141.       for (i = 0; i <= 15; i++) {
  142.          if (intvec = (struct IntVector *) &(SysBase->IntVects[i])) {
  143.             if (intnode = intvec->iv_Node) {
  144.                if ((si_job == SI_LIST) && (intvec->iv_Code) && (intentry = tbAllocPooled(IntPool, sizeof(struct IntEntry)))) {
  145.                   if (! *first)
  146.                      *first = intentry;
  147.                   if (previous)
  148.                      previous->int_next = intentry;
  149.  
  150.                   intentry->int_adr = (char *) intnode;
  151.  
  152.                   if (points2ram((APTR) intvec->iv_Code)) {
  153.                      _sprintf (intentry->int_code, HELL "$%08lx", intvec->iv_Code);
  154.                   } else {
  155.                      _sprintf (intentry->int_code, "$%08lx", intvec->iv_Code);
  156.                   }
  157.                   _sprintf (intentry->int_address, "$%08lx", intnode);
  158.                   strncpy (intentry->int_name, nonetest (intnode->ln_Name), NODENAMELENGTH);
  159.                   _sprintf (intentry->int_pri, "%4ld ", intnode->ln_Pri);
  160.                   _sprintf (intentry->int_data, "$%08lx", intvec->iv_Data);
  161.                   strncpy(intentry->int_num, intTypeShort[i], 31);
  162.                   strcpy (intentry->int_kind, "Handler");
  163.                   intentry->int_number = i;
  164.  
  165.                   intcnt++;
  166.                   previous = intentry;
  167.                } else if ((si_job == SI_FIND) && (! stricmp (name, intnode->ln_Name))) {
  168.                   return ((APTR) intnode);
  169.                } else if ((si_job == SI_REMOVE) && (! stricmp (name, intnode->ln_Name))) {
  170.                   return (NULL);
  171.                }
  172. /*
  173.                if (intvec = (struct IntVector *) intnode->ln_Succ) {
  174.                   intnode = intvec->iv_Node;
  175.                }
  176. */
  177.             } else if ((mark = (char *) intvec->iv_Data) && (mark != (char *) -1)) {
  178.                intr = (struct Interrupt *) ((struct Interrupt *) mark)->is_Node.ln_Succ;
  179.                mark += 4;
  180.  
  181.                while ((intr) && (intr != (struct Interrupt *) mark)) {
  182.                   if ((si_job == SI_LIST) && (intentry = tbAllocPooled(IntPool, sizeof(struct IntEntry)))) {
  183.                      if (! *first)
  184.                         *first = intentry;
  185.                      if (previous)
  186.                         previous->int_next = intentry;
  187.  
  188.                      intentry->int_adr = (char *) intr;
  189.  
  190.                      if (points2ram((APTR) intr->is_Code)) {
  191.                         _sprintf (intentry->int_code, HELL "$%08lx", intr->is_Code);
  192.                      } else {
  193.                         _sprintf (intentry->int_code, "$%08lx", intr->is_Code);
  194.                      }
  195.                      _sprintf (intentry->int_address, "$%08lx", intr);
  196.                      strncpy (intentry->int_name, nonetest (intr->is_Node.ln_Name), NODENAMELENGTH);
  197.                      _sprintf (intentry->int_pri, "%4ld ", intr->is_Node.ln_Pri);
  198.                      _sprintf (intentry->int_data, "$%08lx", intr->is_Data);
  199.                      strncpy (intentry->int_num, intTypeShort[i], 31);
  200.                      strcpy (intentry->int_kind, "Server");
  201.                      intentry->int_number = i;
  202.  
  203.                      intcnt++;
  204.                      previous = intentry;
  205.                   } else if ((si_job == SI_FIND) && (! stricmp (name, intr->is_Node.ln_Name))) {
  206.                      return ((APTR) intr);
  207.                   } else if ((si_job == SI_REMOVE) && (! stricmp (name, intr->is_Node.ln_Name))) {
  208.                      RemIntServer (i, intr);
  209.                      return ((APTR) intr);
  210.                   }
  211.                   intr = (struct Interrupt *) intr->is_Node.ln_Succ;
  212.                }
  213.             }
  214.          }
  215.       }
  216.    }
  217.    if (si_job == SI_LIST) {
  218.       return ((APTR) intcnt);
  219.    }
  220.    return (NULL);
  221. }
  222.  
  223. void PrintInterrupts (char *filename) {
  224.    int   i=1;
  225.    BPTR  handle;
  226.    struct IntEntry *entryp = NULL;
  227.  
  228.    handle = HandlePrintStart (filename);
  229.    if ((handle) && (PrintOneLine (handle, "\n  Address   Pri   Data      Code    NUM IntType Name\n\n"))) {
  230.       if (! WI_Interrupts) {
  231.          i = (int) GetInterrupts (SI_LIST, NULL, &entryp);
  232.       }
  233.       if (i) {
  234.          for (i=0;;i++) {
  235.             if (WI_Interrupts)
  236.                DoMethod (intlist,MUIM_List_GetEntry,i,&entryp);
  237.             if (!entryp) break;
  238.  
  239.             if (entryp->int_code[0] != '$')
  240.                strcpy (tmpstr, entryp->int_code+2);
  241.             else
  242.                strcpy (tmpstr, entryp->int_code);
  243.  
  244.             _sprintf (tmpstr2, " %s %s%s %s  %s%-7.7s %s\n", entryp->int_address, entryp->int_pri, entryp->int_data, tmpstr, entryp->int_num, entryp->int_kind, entryp->int_name);
  245.             if (! (PrintOneLine (handle, tmpstr2)))
  246.                break;
  247.  
  248.             if (! WI_Interrupts)
  249.                entryp = entryp->int_next;
  250.          }
  251.       }
  252.    }
  253.    HandlePrintStop();
  254. }
  255.  
  256. void ShowInterrupts (void) {
  257.    struct IntEntry *intr;
  258.  
  259.    ApplicationSleep();
  260.    set (intlist,MUIA_List_Quiet,TRUE);
  261.    set (BT_IntRemove, MUIA_Disabled, TRUE);
  262.    set (BT_IntMore, MUIA_Disabled, TRUE);
  263.  
  264.    FreeInterrupts();
  265.    intcnt = (int) GetInterrupts (SI_LIST, NULL, &intr);
  266.  
  267.    while (intr) {
  268.       InsertBottomEntry (intlist, (APTR *) &intr);
  269.       intr = intr->int_next;
  270.    }
  271.  
  272.    SetCountText (intcount, intcnt);
  273.    AwakeApplication();
  274.    set (intlist,MUIA_List_Quiet,FALSE);
  275. }
  276.  
  277. void SendIntList (void) {
  278.    struct IntEntry *intr;
  279.  
  280.    FreeInterrupts();
  281.    intcnt = (int) GetInterrupts (SI_LIST, NULL, &intr);
  282.  
  283.    while (intr) {
  284.       SendEncodedEntry ((UBYTE *) intr, sizeof (struct IntEntry));
  285.       intr = intr->int_next;
  286.    }
  287.    FreeInterrupts();
  288. }
  289.  
  290. void GetIntMore (struct IntEntry *intr) {
  291.    unsigned char     *title = "INTERRUPT: ";
  292.    struct   WinFree  *ptr;
  293.  
  294.    if (ptr = AllocWinFree()) {
  295.       ptr->wf_Window = (APTR) WindowObject,
  296.  
  297. //      MUIA_Window_SizeGadget, FALSE,
  298.       MUIA_HelpNode, InterruptsText,
  299.       MUIA_Window_ID, MakeDetailID('.','I','N','T'),
  300.       WindowContents, HGroup,
  301.          Child, VGroup, MUIA_Group_SameWidth, TRUE,
  302.             Child, MyLabel2 ("Name:"),
  303.             Child, MyLabel2 ("Address:\nPri:\nType:"),
  304.             Child, MyLabel2 ("IntName:"),
  305.          End,
  306.          Child, VGroup, MUIA_Group_SameWidth, TRUE,
  307.             Child, intmoretext0 = MyTextObject(),
  308.             Child, HGroup,
  309.                Child, intmoretext1 = MyTextObject2(),
  310.                Child, MyLabel ("Data:\nCode:\nIntType:"),
  311.                Child, intmoretext2 = MyTextObject2(),
  312.             End,
  313.             Child, intmoretext3 = MyTextObject(),
  314.          End,
  315.       End, End;
  316.  
  317.       if (ptr->wf_Window) {
  318.          MySetContents (intmoretext1, ESC "r%s\n" ESC "c%ld\n" ESC "c%s", intr->int_address, ((struct Node *) intr->int_adr)->ln_Pri, GetNodeType (((struct Node *) intr->int_adr)->ln_Type));
  319.          MySetContents (intmoretext2, ESC "r%s\n%s\n" DUNKEL ESC "c%s", intr->int_data, intr->int_code, intr->int_kind);
  320.          MySetContents (intmoretext3, intType[intr->int_number]);
  321.  
  322.          HandleWindowOpen (ptr, title, intr->int_name);
  323.          MySetContents (intmoretext0, intr->int_name);
  324.          HandleWindowClose (ptr);
  325.       }
  326.    }
  327. }
  328.  
  329.  
  330. char interrupts_title[WINDOWTITLELEN];
  331.  
  332. void InterruptsWindow (BOOL state) {
  333.    if (state) {
  334.       if (WI_Interrupts) {
  335.          ShowInterrupts();
  336.       } else {
  337.          WI_Interrupts = WindowObject,
  338.          MUIA_Window_Title, MyGetWindowTitle (interrupts_title, "INTERRUPTS"),
  339.          MUIA_HelpNode, InterruptsText,
  340.          MUIA_Window_ID, MakeListID('I','N','T','E'),
  341.          WindowContents, VGroup,
  342.             Child, intlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8,COL=4 DELTA=8,COL=5 DELTA=8,COL=6",&intlist_dsphook),
  343.             Child, MyBelowListview (&inttext, &intcount),
  344.             Child, MyVSpace(2),
  345.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  346.                Child, BT_IntUpdate   = KeyButtonA (UpdateText,ID_INTUPDATE),
  347.                Child, BT_IntPrint    = KeyButtonA (PrintText ,ID_INTPRINT),
  348.                Child, BT_IntRemove   = KeyButtonA (RemoveText,ID_INTREMOVE),
  349.                Child, BT_IntMore     = KeyButtonA (MoreText  ,ID_INTMORE),
  350.                Child, BT_IntExit     = KeyButtonA (ExitText  ,ID_INTEXIT),
  351.             End,
  352.          End, End;
  353.  
  354.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_Interrupts);
  355.          DoMethod (WI_Interrupts,MUIM_Window_SetCycleChain,intlist,BT_IntUpdate,BT_IntPrint,BT_IntRemove,BT_IntMore,BT_IntExit,NULL);
  356.  
  357.          SetCloseRequest (WI_Interrupts,ID_INTEXIT);
  358.          SetListActive (intlist,ID_INTLV_ACTIVE);
  359.          SetListviewDoubleClick (intlist,ID_INTMORE);
  360.  
  361.          ShowInterrupts();
  362.  
  363.          SetWindowOpen (WI_Interrupts,intlist,ID_INTEXIT);
  364.       }
  365.    } else if ((! state) && (WI_Interrupts)) {
  366.       SetWindowClose (WI_Interrupts,TRUE);
  367.  
  368.       FreeInterrupts();
  369.  
  370.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Interrupts);
  371.       MUI_DisposeObject (WI_Interrupts);
  372.       WI_Interrupts = NULL;
  373.       intlist = NULL;
  374.    }
  375. }
  376.  
  377.